package com.castle.fortress.admin.oa.service.impl;

import cn.hutool.core.util.StrUtil;
import com.castle.fortress.admin.utils.BizCommonUtil;
import com.castle.fortress.common.utils.ConvertUtil;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.castle.fortress.admin.oa.entity.AttendanceSettingDateEntity;
import com.castle.fortress.admin.oa.dto.AttendanceSettingDateDto;
import com.castle.fortress.admin.oa.mapper.AttendanceSettingDateMapper;
import com.castle.fortress.admin.oa.service.AttendanceSettingDateService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.util.List;

/**
 * 考勤时间设置 服务实现类
 *
 * @author whc
 * @since 2022-11-03
 */
@Service
public class AttendanceSettingDateServiceImpl extends ServiceImpl<AttendanceSettingDateMapper, AttendanceSettingDateEntity> implements AttendanceSettingDateService {
    /**
    * 获取查询条件
    * @param attendanceSettingDateDto
    * @return
    */
    public QueryWrapper<AttendanceSettingDateEntity> getWrapper(AttendanceSettingDateDto attendanceSettingDateDto){
        QueryWrapper<AttendanceSettingDateEntity> wrapper= new QueryWrapper();
        if(attendanceSettingDateDto != null){
            AttendanceSettingDateEntity attendanceSettingDateEntity = ConvertUtil.transformObj(attendanceSettingDateDto,AttendanceSettingDateEntity.class);
            wrapper.eq(attendanceSettingDateEntity.getSettId() != null,"sett_id",attendanceSettingDateEntity.getSettId());
            wrapper.orderByDesc("create_time");
        }
        return wrapper;
    }


    @Override
    public IPage<AttendanceSettingDateDto> pageAttendanceSettingDate(Page<AttendanceSettingDateDto> page, AttendanceSettingDateDto attendanceSettingDateDto) {
        QueryWrapper<AttendanceSettingDateEntity> wrapper = getWrapper(attendanceSettingDateDto);
        Page<AttendanceSettingDateEntity> pageEntity = new Page(page.getCurrent(), page.getSize());
        Page<AttendanceSettingDateEntity> attendanceSettingDatePage=baseMapper.selectPage(pageEntity,wrapper);
        Page<AttendanceSettingDateDto> pageDto = new Page(attendanceSettingDatePage.getCurrent(), attendanceSettingDatePage.getSize(),attendanceSettingDatePage.getTotal());
        pageDto.setRecords(ConvertUtil.transformObjList(attendanceSettingDatePage.getRecords(),AttendanceSettingDateDto.class));
        return pageDto;
    }

    @Override
    public IPage<AttendanceSettingDateDto> pageAttendanceSettingDateExtends(Page<AttendanceSettingDateDto> page, AttendanceSettingDateDto attendanceSettingDateDto){
        Map<String,Long> pageMap = BizCommonUtil.getPageParam(page);
        AttendanceSettingDateEntity attendanceSettingDateEntity = ConvertUtil.transformObj(attendanceSettingDateDto,AttendanceSettingDateEntity.class);
        List<AttendanceSettingDateEntity> attendanceSettingDateList=baseMapper.extendsList(pageMap,attendanceSettingDateEntity);
        Long total = baseMapper.extendsCount(attendanceSettingDateEntity);
        Page<AttendanceSettingDateDto> pageDto = new Page(page.getCurrent(), page.getSize(),total);
        pageDto.setRecords(ConvertUtil.transformObjList(attendanceSettingDateList,AttendanceSettingDateDto.class));
        return pageDto;
    }
    @Override
    public AttendanceSettingDateDto getByIdExtends(Long id){
        AttendanceSettingDateEntity  attendanceSettingDateEntity = baseMapper.getByIdExtends(id);
        return ConvertUtil.transformObj(attendanceSettingDateEntity,AttendanceSettingDateDto.class);
    }

    @Override
    public List<AttendanceSettingDateDto> listAttendanceSettingDate(AttendanceSettingDateDto attendanceSettingDateDto){
        QueryWrapper<AttendanceSettingDateEntity> wrapper = getWrapper(attendanceSettingDateDto);
        List<AttendanceSettingDateEntity> list = baseMapper.selectList(wrapper);
        return ConvertUtil.transformObjList(list,AttendanceSettingDateDto.class);
    }
}

